<template>
	<view>

		<input type="text" v-model="name" placeholder="课程名" />
		<view class="uni-title uni-common-pl">上课时间</view>
		<view class="uni-list">
			<view class="uni-list-cell">
				<view class="uni-list-cell-left">
					当前选择
				</view>
				<view class="uni-list-cell-db">
					<picker @change="bindPickerChange" :value="index" :range="array" range-key="name">
						<view class="uni-input">{{array[index].name}}</view>
					</picker>
				</view>
			</view>
		</view>
		<input  type="number"  v-model="time" placeholder="开始课时" />
		<input  type="number"  v-model="num" placeholder="课程节数" />
		<button @click="add">新增</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'picker',
				array: [{name:'周一'},{name: '周二'}, {name:'周三'}, {name:'周四'}, {name:'周五'}, {name:'周六'}, {name:'周日'}],
				index: 0,
				multiArray: [
					['亚洲', '欧洲'],
					['中国', '日本'],
					['北京', '上海', '广州']
				],
				multiIndex: [0, 0, 0],
				date: getDate({
					format: true
				}),
				startDate:getDate('start'),
				endDate:getDate('end'),
				num: '',
				name:'',
				time: ''
			}
		},
		methods: {
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为：' + e.detail.value)
				this.index = e.detail.value
			},
			bindMultiPickerColumnChange: function(e) {
				console.log('修改的列为：' + e.detail.column + '，值为：' + e.detail.value)
				this.multiIndex[e.detail.column] = e.detail.value
				switch (e.detail.column) {
					case 0: //拖动第1列
						switch (this.multiIndex[0]) {
							case 0:
								this.multiArray[1] = ['中国', '日本']
								this.multiArray[2] = ['北京', '上海', '广州']
								break
							case 1:
								this.multiArray[1] = ['英国', '法国']
								this.multiArray[2] = ['伦敦', '曼彻斯特']
								break
						}
						this.multiIndex.splice(1, 1, 0)
						this.multiIndex.splice(2, 1, 0)
						break
					case 1: //拖动第2列
						switch (this.multiIndex[0]) { //判断第一列是什么
							case 0:
								switch (this.multiIndex[1]) {
									case 0:
										this.multiArray[2] = ['北京', '上海', '广州']
										break
									case 1:
										this.multiArray[2] = ['东京','北海道']
										break
								}
								break
							case 1:
								switch (this.multiIndex[1]) {
									case 0:
										this.multiArray[2] = ['伦敦', '曼彻斯特']
										break
									case 1:
										this.multiArray[2] = ['巴黎', '马赛']
										break
								}
								break
						}
						this.multiIndex.splice(2, 1, 0)
						break
				}
				this.$forceUpdate()
			},
			bindDateChange: function(e) {
				this.date = e.detail.value
			},
			bindTimeChange: function(e) {
				this.time = e.detail.value
			},
				
			add(){
				var classer = getApp().globalData.classer;
				var cell = getApp().globalData.classCell;
				cell.start=this.$data.index + "-" + this.$data.time;
				cell.name = this.$data.name;
				cell.num = this.$data.num;
				cell.color = this.RamColor();
				var str = JSON.stringify(cell);
				
				getApp().globalData.classer.push(JSON.parse(str));
				console.log(getApp().globalData.classer);
				
				uni.request({
				    url: 'https://university-android-1.sidcloud.cn/api/consumer/SetInfo', //仅为示例，并非真实接口地址。
				    data: {
						data:JSON.stringify(getApp().globalData.classer)
				    },
				    header: {
				        'Accept': 'application/json' ,
						'Authorization': 'Bearer '+getApp().globalData.token
				    },
				    success: (res) => {
						
						
						if(res.data.code!=200){
							uni.showToast({
								title:"网络错误，请检查"
							})
							
						}else{
				uni.navigateTo({
				    url: '/pages/class/class',
				})
						}
				    }
				});
			},
			RamColor(){
					var ram = Math.floor(Math.random() * 3 + 1);
						
					switch (ram){
					case 1:
						return "#669999"; //grey
					case 2:
						return "#ff5739";//red
					default:
						return "#9bbeff";//blue
					}
				},
		
		}
	}
</script>

<style>
.uni-picker-tips {
	font-size: 12px;
	color: #666;
	margin-bottom: 15px;
	padding: 0 15px;
	/* text-align: right; */
}
</style>
